<!--
* 开源版本请务必保留此注释头信息，若删除gemframe官方保留所有法律责任追究！
* 本软件受国家版权局知识产权以及国家计算机软件著作权保护（登记号：2018SR503328）
* 不得恶意分享产品源代码、二次转售等，违者必究。
* Copyright (c) 2020 gemframework all rights reserved.
* http://www.gemframework.com
* 版权所有，侵权必究！
-->
<!DOCTYPE html>
<html lang="zh-cn" class="fullscreen-bg" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/links :: common_header(~{::title},~{::link},~{})">
    <script>if (window !== top) top.location.replace(location.href);</script>
    <title>请您登录 | GemFrame开源权限管理系统v1.0.0</title>
    <link th:href="@{/coral/css/login.css}" rel="stylesheet">
</head>
<body>
<div class="login-wrapper">
    <div class="login-header">
        <img th:src="@{/coral/images/logo.png}">
        捷码开源权限管理系统V1.0
    </div>
    <form class="layui-form">
        <h2>用户登录</h2>
        <div class="layui-form-item layui-input-icon-group">
            <i class="layui-icon layui-icon-username"></i>
            <input class="layui-input" name="username" placeholder="请输入登录账号" autocomplete="off"
                   lay-verType="tips" lay-verify="required" required value="admin"/>
        </div>
        <div class="layui-form-item layui-input-icon-group">
            <i class="layui-icon layui-icon-password"></i>
            <input class="layui-input" name="password" placeholder="请输入登录密码" type="password"
                   lay-verType="tips" lay-verify="required" required value="123456"/>
        </div>
        <div class="layui-form-item layui-input-icon-group login-captcha-group">
            <i class="layui-icon layui-icon-auz"></i>
            <input class="layui-input" name="validCode" placeholder="请输入验证码" autocomplete="off"
                   lay-verType="tips" lay-verify="required" required/>
            <img class="login-captcha" src="captcha/code" width="130px" height="48px" />
        </div>
        <div class="layui-form-item">
            <input type="checkbox" name="rememberMe" title="记住密码" lay-skin="primary" checked>
            <a href="javascript:;" class="layui-link pull-right">注册账号</a>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid" lay-filter="loginSubmit" lay-submit>登录</button>
        </div>
        <div class="layui-form-item login-oauth-group text-center">
            <a href="javascript:;"><i class="layui-icon layui-icon-login-qq" style="color:#3492ed;"></i></a>&emsp;
            <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat" style="color:#4daf29;"></i></a>&emsp;
            <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo" style="color:#CF1900;"></i></a>
        </div>
    </form>
</div>
<div class="login-copyright">
    <p>
        <span><a href="http://www.gemframework.com" target="_blank">项目官网</a></span>
         | <span><a href="http://www.gemframework.com/bbs" target="_blank">社区交流</a></span>
         | <span><a href="https://gitee.com/gemteam" target="_blank">源码获取</a></span>
         | <span><a href="login_layui.html">旧版</a></span>
         | <span><a href="login_oschina.html">仿开源中国</a></span>
         | <span><a href="login_gitee.html">仿码云界面</a></span>
    </p>
    Copyright © [[${#dates.format(new java.util.Date().getTime(), 'yyyy')}]]
    <a href="http://www.gemframework.com" target="_blank"> gemframework.com </a>版权所有
</div>


<!-- js部分 -->
<div th:replace="common/scripts :: common"></div>
<div th:replace="common/scripts :: jquery"></div>
<div th:replace="common/scripts :: encode"></div>
<script>
    layui.use(['admin','layer','form','notice'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var notice = layui.notice;
        var admin = layui.admin;

        //登录超时处理
        if(top.location.href != self.location.href){
            layer.alert("登录超时，请重新登录！",{
                closeBtn: 0
                ,icon: 5
                ,anim: 4 //动画类型
            },function(){
                top.location.href=self.location.href;
            });
        }

        // 表单提交
        form.on('submit(loginSubmit)', function (obj) {
            obj.field.password = encode64(obj.field.password);
            $.ajax({
                type: "post",
                url: "login",
                data: obj.field,
                async:true, // 异步请求
                cache:false, // 设置为 false 将不缓存此页面
                dataType: "json", // 返回对象
                success: function(res) {
                    if (res.code == "0") {
                        layer.msg('登录成功', {icon: 1, time: 1500}, function () {
                            location.replace('index')
                        });
                    }else {
                        $(".login-captcha").click()
                        notice.error({
                            title: '登录失败',
                            message: "错误码：["+res.code+"]    错误消息："+res.msg+"",
                            theme: "light",
                            displayMode: 2,
                            layout:2
                        });
                    }
                },
                error: function(e) {
                    // 请求失败函数
                    console.log("error:"+JSON.stringify(e));
                    layer.msg("操作失败，请检查是否有相关操作权限！");
                }
            })
            return false;
        });

        // 图形验证码
        $('.login-captcha').click(function () {
            this.src = this.src + '?t=' + (new Date).getTime();
        });
        $(".login-captcha").click()

        //主题随机
        var theme = ["colorful","blue","green","purple","pink","cyan"];
        var i = Math.round(Math.random()*5);
        // admin.changeTheme("theme-"+theme[i]);
        admin.changeTheme("theme-"+theme[1]);
        var img_url = ["coral/images/bg_login5.jpg"
            ,"coral/images/bg_login.png"
            ,"coral/images/bg_login1.png"
            ,"coral/images/bg_login2.png"
            ,"coral/images/bg_login3.png"
            ,"coral/images/bg_login4.jpg"
        ];
        // $("body").css("background-image","url("+img_url[i]+")");
        $("body").css("background-image","url("+img_url[5]+")");
    });

</script>
</body>
</html>